package com.atguigu.controller;

import com.atguigu.pojo.User;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user")
@Tag(name = "用户控制器")
public class UserController {

    @Operation(summary = "获取用户信息列表")
    @GetMapping
    public List<User> list(){
        return List.of(
                new User(1l,"jim",20,"jim@126.com"),
                new User(2l,"tom",21,"jim@126.com"),
                new User(3l,"jack",30,"jim@126.com"),
                new User(4l,"lucy",10,"jim@126.com")
        );
    }

    @Operation(summary = "获取指定的用户信息")
    @GetMapping("/{id}")
    public User getById(@Parameter(name = "用户ID") @PathVariable Integer id){
        return new User(3l,"jack",30,"jim@126.com");
    }

    @PostMapping
    public User save( @RequestBody User user){
        return user;
    }

}
